﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace WizzardTheGame
{
    class ObjectText
    {
        private const int FADEINCREMENT = 3;
        private string text;
        private Vector2 position;
        private Color color;
        private SpriteFont font;
        private int alphaValue;
        private double fadeDelay;
        private bool isVisible;
       
        #region Properties

        public string Text {
            get { return text; }
            set { text = value; }
        }

        public Vector2 Position {
            get { return position; }
            set { position = value; }
        }

        public Color Color {
            get { return color; }
            set { color = value; }
        }

        public SpriteFont Font
        {
            get { return font; }
            set { font = value; }
        }

        public int AlphaValue
        {
            get { return alphaValue; }
            set { alphaValue = value; }
        }

        protected double FadeDelay
        {
            get { return fadeDelay; }
            set { fadeDelay = value; }
        }

        public bool IsVisible
        {
            get { return isVisible; }
            set { isVisible = value; }
        }

        #endregion

        public void Draw()
        {
            if (IsVisible)
            {
                GameWorld.getInstance().SpriteBatch.DrawString(Font, Text, Position, new Color(Color, (byte)AlphaValue));
            }
        }

        public void Draw(GameTime gameTime)
        {
            if (IsVisible)
            {

                if (alphaValue > 0)
                {
                    FadeDelay -= gameTime.ElapsedGameTime.TotalSeconds;

                    if (FadeDelay <= 0)
                    {
                        FadeDelay = 0.035;

                        AlphaValue = (int)MathHelper.Clamp(AlphaValue - FADEINCREMENT, 0, 255);
                    }

                    Draw();
                }
                else
                {
                    IsVisible = false;
                }
            }


        }
    }
}
